package dams

import (
	"fmt"
	"goPlay/dams/container"
	"goPlay/logger"
	"strconv"
	"time"
)

func GetStudentStruct(studentId int) *container.StudentRecordContainerTest {
	var s *container.StudentRecordContainerTest
	key := strconv.Itoa(studentId)
	start_time := time.Now()
	fmt.Println("start get struct:", start_time)
	if v, found := sc.Get(key); found {
		logger.Debug("find:", key, v)
		ss, _ := v.Object.(*container.StudentRecordContainerTest)
		s = ss
		fmt.Println("find:", ss)
	} else {
		logger.Debug("not find:", key)
		s = new(container.StudentRecordContainerTest)
		s.Init(key)
		UpdateCache(sc, key, s)
	}
	end_time := time.Now()
	fmt.Println("end get struct:", end_time, "cost time:", end_time.Nanosecond()-start_time.Nanosecond())
	return s
}

func ComeHere(studentId int) {
	var s *container.StudentRecordContainerTest
	s = GetStudentStruct(studentId)
	s.Come()
	UpdateCache(sc, strconv.Itoa(studentId), s)
}

func GetStudentRedis(studentId int) *container.StudentRecordContainerTest {
	var s *container.StudentRecordContainerTest
	key := strconv.Itoa(studentId)
	start_time := time.Now()
	fmt.Println("start get struct:", start_time)

	end_time := time.Now()
	fmt.Println("end get struct:", end_time, "cost time:", end_time.Nanosecond()-start_time.Nanosecond())
	return s
}

// func GetKeyRedis()
